package com.tianhui.consignortwofei.mvp.ui.activity.audit;

import android.widget.EditText;

import androidx.fragment.app.Fragment;

import com.fgs.common.CommonPresenter;
import com.fgs.common.CommonView;
import com.fgs.common.adapter.FragmentPagerAdapter;
import com.fgs.common.widget.CustomViewPager;
import com.flyco.tablayout.SlidingTabLayout;
import com.tianhui.consignortwofei.R;
import com.tianhui.consignortwofei.base.BaseActivity;
import com.tianhui.consignortwofei.interf.OnSearchClearListener;
import com.tianhui.consignortwofei.interf.OnSearchClickListener;

import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * @author fgs
 * @date 2020/8/27
 * @description
 **/
public abstract class SearchActivity<V extends CommonView, P extends CommonPresenter<V>> extends BaseActivity<V, P> implements OnSearchClearListener {

    @BindView(R.id.layout_search_editText)
    EditText mSearchEditText;
    @BindView(R.id.activity_driver_list_tabLayout)
    SlidingTabLayout mTabLayout;
    @BindView(R.id.activity_driver_list_viewPager)
    CustomViewPager mViewPager;

    private OnSearchClickListener mOnSearchClickListener;

    private FragmentPagerAdapter mAdapter;


    @Override
    public int getLayoutId() {
        return R.layout.activity_driver_list;
    }


    @Override
    public void init() {

        mAdapter = new FragmentPagerAdapter(getSupportFragmentManager());
        mAdapter.setTabTitles(getTabTitles());
        mAdapter.setFragments(getFragments());
        mViewPager.setAdapter(mAdapter);
        mViewPager.setOffscreenPageLimit(getFragments().size());
        mTabLayout.setViewPager(mViewPager);

    }

    public abstract List<Fragment> getFragments();

    public abstract List<String> getTabTitles();


    @OnClick(R.id.layout_search_textView)
    public void searchVehicle() {
        String searchKey = mSearchEditText.getText().toString().trim();
//        if (TextUtils.isEmpty(searchKey)) {
//            showToast("请输入关键字");
//            return;
//        }
        mOnSearchClickListener.onSearch(searchKey);
    }

    public void setOnSearchClickListener(OnSearchClickListener onSearchClickListener) {
        this.mOnSearchClickListener = onSearchClickListener;
    }

    @Override
    public void onSearchClear() {
        mSearchEditText.setText("");
    }

    public void setSearchKeyHint(String hint) {
        mSearchEditText.setHint(hint);
    }


}
